using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.IO;
using System.Configuration;
namespace PFDB.IntelisenceLib
{
    public class Intelisence
    {
        Dictionary<string,ArrayList> a =new Dictionary<string,ArrayList>();
        ArrayList empty = new ArrayList();
        string word;
        public Intelisence(string lang)
        {
			string test=ConfigurationSettings.AppSettings["DictionariesPath"];
			string dictPath=Path.Combine(test, lang + ".lang");
			StreamReader reader = new StreamReader(dictPath);
            string word;
            string part;
			while (!reader.EndOfStream)
			{
				word = reader.ReadLine().Trim();
				for (int i = 1; i <= word.Length; i++)
				{
					part = word.Substring(0, i);
					if (a.ContainsKey(part))
					{
						a[part].Add(word);
					}
					else
					{
						a.Add(part, new ArrayList());
						a[part].Add(word);
					}
				}
			}
        }
        public ArrayList GetList(string key)
        {
            this.word = key.ToUpper();
            if (a.ContainsKey(word))
                return a[word];
            else
                return empty;
        }
        public bool ContainsWord(string word)
        {
            this.word = word.ToUpper();
            if (a.ContainsKey(this.word))
                return a[this.word].Contains(this.word);
            else
                return false;
        }
        public void addToFile()
        {
            StreamWriter writer = new StreamWriter("C:/test.txt");
            foreach (KeyValuePair<string,ArrayList> key in a)
            {
                foreach (object value in key.Value)
                {
                    writer.WriteLine(key.Key+"-"+(string)value);
                }
            }
        }
    }
}